import os
import sys
# 用前缀和会更方便拿到区间和
from itertools import accumulate

imput = sys.stdin.readline
n, q = map(int, input().split())

a = list(map(int, input().split()))

# from bit0 to bit31
a_bit = []
for i in range(31):
    now = []
    for x in a:
        now.append((x >> i) & 1)
    a_bit.append(list(accumulate(now)))
# print(a_bit)
out = []
for _ in range(q):
    l, r = map(int, input().split())
    l -= 1
    r -= 1
    ans = 0
    for i in range(31):
        if l == 0:
            now = a_bit[i][r]
        else:
            now = a_bit[i][r] - a_bit[i][l - 1]
        if now > 0:
            ans += (1 << i)
    out.append(ans)
print(*out, sep='\n')
